Connecting to MySQL(WAMP) database with PHP -
here trying do.
i have index.php page accepts user input , transfers infosubmitted.php
<?php include('header.php'); ?> <body> <form action="infosubmitted.php" method="post" id="infosubmitted"> <div id="header"> <h1><strong>enter in data</h1></strong> </div> <div id="main"> <table border="0" width="75%"> <tr> <td align="right" width="10%">first name: </td> <td><input type="text" name="fname" id="fname" size="20" /></td> </tr> <tr> <td align="right" width="10%">last name: </td> <td><input type="text" name="lname" id="lname" size="20" /></td> </tr> <tr> <td align="right" width="10%">age: </td> <td><input type="text" name="age" id="age" size="3" /></td> </tr> <tr> <td align="right" width="10%">city: </td> <td><input type="text" name="city" id="city" size="20" /></td> </tr> </table> <input type="submit" /> </div> </body> <?php include('footer.php'); ?> now, trying variables , store them in database called test in table called people
here dbconnect.php
<?php // set database access information constants define('db_user', 'root'); define('db_password', 'phpmyadmin'); define('db_host', 'localhost'); define('db_name', 'test'); ?> and here model.php
<?php // model totals of wreath orders require_once("dbconnect.php"); // connect database , check errors @ $dbc = mysqli_connect(db_host, db_user, db_password, db_name); $connection_error = $dbc->connect_error; if ($connection_error != null) { echo "<p>error connectiong database: $connection_error</p>"; exit(); } ?> here infosubmitted.php
<?php require_once("model.php"); $fname = $_post['fname']; $lname = $_post['lname']; $age = $_post['age']; $city = $_post['city']; insertintotable($fname, $lname, $age, $city); function insertintotable($fname, $lname, $age, $city){ global $dbc; $insertrow = 'insert people(fname, lname, age, city) values('$fname', '$lname', '$age', '$city')'; $result = $dbc->query($insertrow); header('location: getinformation.php'); } ?> then want redirected getinformation.php take record out of database can store variables.
<?php include('model.php'); include('header.php'); $fname = $people['fname']; $lname = $people['lname']; $age = $people['age']; $city = $people['city']; $dbc->close(); ?> <div id="header"> <h1><strong>this information submitted</h1></strong> </div> <div id="main"> <table> <tr> <td>first name:</td> <td><?php echo $fname; ?></td> </tr> <tr> <td>last name:</td> <td><?php echo $lname; ?></td> </tr> <tr> <td>age:</td> <td><?php echo $age; ?></td> </tr> <tr> <td>city:</td> <td><?php echo $city; ?></td> </tr> </table> </div> <?php include('footer.php'); ?> i error
parse error: syntax error, unexpected t_variable in c:\program files\wamp\www\testwebpage\model\infosubmitted.php on line 17
i know keep passing variables index info submitted , getinformation trying grasp on connecting database.
i want have user enter data, have data sent page data put table redirect new page , have information table dumped variables can put them on screen.
wrap statement double quotes instead of single quotes.
$insertrow = "insert people (fname, lname, age, city) values('$fname', '$lname', '$age', '$city')"; in it's current state queries unescaped , vulnerable sql injection. should consider escaping them mysql_real_escape_string() or using similar methods.
the entire ext/mysql php extension, provides functions named prefix mysql_, officially deprecated of php v5.5.0 , removed in future. consider switching mysqli or pdo
Comments
Post a Comment