rawkinyeti Posted August 19, 2011 Share Posted August 19, 2011 So i have two update scripts using prepared statements. One works fine and updates the record, while the other give me a "Call to a member function bind_param() on a non-object". They are almost identical minus the variables in them. Ive been staring at this for a day now and still nothing. If anyone has any insight i would love to hear from you. This is the code that works... <?phpsession_start();/*** connect to database ***/ /*** mysql hostname ***/ $mysql_hostname = '#######'; /*** mysql username ***/ $mysql_username = '#####'; /*** mysql password ***/ $mysql_password = '######'; /*** database name ***/ $mysql_dbname = 'propertyregistration'; $conn = mysqli_connect( $mysql_hostname, $mysql_username, $mysql_password, $mysql_dbname ); $last_name = trim($_POST['lastname']); $first_name = trim($_POST['firstname']); $address = trim($_POST['address']); $city = trim($_POST['city']); $state = trim($_POST['state']); $zip = trim($_POST['zip']); $phone = trim($_POST['phone']); $email = trim($_POST['email']); $student = $_GET['student_id']; $username = $_SESSION['username']; $_SESSION['username'] = $username; $dbh = new mysqli($mysql_hostname, $mysql_username, $mysql_password, $mysql_dbname);$stmt = $dbh->prepare("UPDATE personal_info SET last_name=?, first_name=?, address=?, city=?, state=?, zip=?, phone_number=?, email=? WHERE student_id =$student");$stmt->bind_param("ssssssss", $last_name, $first_name, $address, $city, $state, $zip, $phone, $email);$stmt->execute();header("Location: thankyou1.php");?> This code does not <?phpsession_start();/*** connect to database ***/ /*** mysql hostname ***/ $mysql_hostname = '#####'; /*** mysql username ***/ $mysql_username = '#####'; /*** mysql password ***/ $mysql_password = '######'; /*** database name ***/ $mysql_dbname = 'propertyregistration'; $conn = mysqli_connect( $mysql_hostname, $mysql_username, $mysql_password, $mysql_dbname ); $item_id = trim($_POST['itemid']); $uid = trim($_POST['uid']); $manufacturer = trim($_POST['manufacturer']); $model = trim($_POST['model']); $color = trim($_POST['color']); $more = trim($_POST['more']); $username = $_SESSION['username'];$_SESSION['username'] = $username;$serial= $_GET['serial_number'];$dbh = new mysqli($mysql_hostname, $mysql_username, $mysql_password, $mysql_dbname);$stmt = $dbh->prepare("UPDATE item_info SET item_id=?, uid=?, manufacturer=?, model=?, color=?, more=? WHERE serial_number =$serial");$stmt->bind_param("ssssss", $item_id, $uid, $manufacturer, $model, $color, $more);$stmt->execute();header("Location: thankyou1.php");?> Thank you in advance Link to comment Share on other sites More sharing options...
rawkinyeti Posted August 19, 2011 Author Share Posted August 19, 2011 Ok i think i got it. Its weird i can do it one way for one of the scripts but its slight different for the next one to work. The first one from last post is still fine, ill repost the newly fixed one. Im new to prepared statements and i have to say im not liking them. Having learned the "standard" php connect to mysql i feel like im trying to learn Spanish after i just went ahead an learned Russian.....Changes are in bold <?phpsession_start();/*** connect to database ***/ /*** mysql hostname ***/ $mysql_hostname = '****'; /*** mysql username ***/ $mysql_username = '*****'; /*** mysql password ***/ $mysql_password = '******'; /*** database name ***/ $mysql_dbname = 'propertyregistration'; $conn = mysqli_connect( $mysql_hostname, $mysql_username, $mysql_password, $mysql_dbname ); $item_id = trim($_POST['itemid']); $uid = trim($_POST['uid']); $manufacturer = trim($_POST['manufacturer']); $model = trim($_POST['model']); $color = trim($_POST['color']); $more = trim($_POST['more']); $username = $_SESSION['username'];$_SESSION['username'] = $username;$serial= $_GET['serial_number'];$dbh = new mysqli($mysql_hostname, $mysql_username, $mysql_password, $mysql_dbname);$stmt = $dbh->prepare("UPDATE item_info SET item_id =?, uid =?, manufacturer =?, model =?, color =?, more =? WHERE [b]serial_number =?[/b]");$stmt->bind_param("sssssss", $item_id, $uid, $manufacturer, $model, $color, $more, [b]$serial[/b]);$stmt->execute();header("Location: thankyou1.php");?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.