updating database help

hello phphelp.com community,

I am confused on my codes right now, and i dont know what might me the error,
I want to update multiple rows in my database using sql command and php.

guys please elaborate more your explanations, im a student working on my case study, im just a newbie.
your replies will be appreciated thank you.
btw sorry for my english.

firstpart
[php]

<?php $host = "localhost"; $user = "root"; $pass = ""; $db = "student"; mysql_connect($host, $user, $pass); mysql_select_db($db); session_start(); $studID = $_SESSION['studID']; $sql = mysql_query("SELECT * FROM student WHERE studentID='".$studID."' "); if (mysql_num_rows($sql) == 1 ) { $row = mysql_fetch_assoc($sql); $_SESSION['studentYear'] = $row['year']; $_SESSION['studentfname'] = $row['firstname']; $_SESSION['studentlname'] = $row['lastname']; $_SESSION['studentaverage'] = $row['average']; if($studyear == '1'){ if (isset($_POST['submit'])) { header("Location: enrollfreshmen.php"); } } else if($studyear == '2'){ if (isset($_POST['submit'])) { header("Location: enrollsophomore.php"); } } } else { echo"Database error."; exit(); } ?>

[/php]

enrollfreshmen.php
[php]

<?php $host = "localhost"; $user = "root"; $pass = ""; $db = "enrolledfresmen"; //nvm the spelling ill change it. $table = "student"; mysql_connect($host, $user, $pass); mysql_select_db($db); session_start(); $studyear = $_SESSION['studentYear']; $studfname = $_SESSION['studentfname']; $studyear = $_SESSION['studentlname']; $studaverage = $_SESSION['studentaverage']; $studID = $_SESSION['studID']; $sql = "INSERT INTO $table (studentID, firstname, lastname, year, average, date) VALUES ('".$studID."', '".$studfname."', '".$studlname."', '".$studyear."', '".$studaverage."', CURRENT_TIMESTAMP )"; ?>

[/php]

[ol][li][php]if($studyear == ‘1’){[/php] $studyear has not been defined anywhere… maybe you mean $_SESSION[‘studentYear’] [/li]
[li]You say you want to update rows, but you are not making any update sql-statements.[/li]
[li][php]$sql = “INSERT INTO $table (studentID, firstname, lastname, year, average, date) VALUES (’”.$studID."’, ‘".$studfname."’, ‘".$studlname."’, ‘".$studyear."’, ‘".$studaverage."’, CURRENT_TIMESTAMP )";[/php] you define a query in a string, but you never send it to the database.[/li]
[li]Using header calls seems unnecessary. You could just use include-command and you wouldn’t need session at all for this.[/li][/ol]

Sponsor our Newsletter | Privacy Policy | Terms of Service